﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FileDelete
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label6.Text = System.DateTime.Now.ToString();
        }

        /// <summary>
        /// 文件路径获取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = FileDeleteTools.SelectPath();//赋值文件路径            
        }       

        /// <summary>
        /// 删除【根据路径删除】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()) || string.IsNullOrEmpty(textBox2.Text.Trim()))
            {
                MessageBox.Show("请填写完整的路径和日期格式！");
                return;
            }

            var srcPath = textBox1.Text;
            var dateString = DateTime.Now.ToString(textBox2.Text.Trim());
            var result = FileDeleteTools.FileDelete(srcPath, dateString);
            if (result)
            {
                MessageBox.Show("删除成功！");
            }
        }

        
    }
}
